Function.prototype.limit = function(max) {
	if (max==0) return;
	var stop = false, execute = true;
	var args = arguments;
	var that = this;
	var interval = Math.ceil(1000/max);
	return function() {
		if (!stop) {
			stop = true;
			setTimeout(function(){
				stop = false;
				if (execute) {
					args.callee.apply(that, args);
					execute = false;
				}
			}, interval);
			return that.apply(this, args);
		} else {
			execute = true;
		}
	}
}